package org.example.day20241227.operators;

import org.apache.flink.api.common.RuntimeExecutionMode;
import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
/**
 * @className: MapDemo
 * @author: 孙磊
 * @date: 2024/12/29 17:01
 * @Version: 1.0
 * @description: 输入一个元素同时输出一个元素。
 * 1.1.map算子,读一个数组数据并将每个元素增加10,得到一个新的数据集;
 */
public class MapDemo {
    public static void main(String[] args) throws Exception {
        final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setRuntimeMode(RuntimeExecutionMode.BATCH);
        env.setParallelism(1);

        DataStreamSource<Integer> ds = env.fromData(1, 2, 3, 4, 5, 6, 7, 8, 9, 0);
        ds.map(new MapFunction<Integer, Integer>() {
            @Override
            public Integer map(Integer val) throws Exception {
                return val * 10;
            }
        }).print();

        env.execute();
    }
}
